package activity.addCamera.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.hichip.campro.R;
import com.hichip.content.HiChipDefines;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by lt on 2018\3\9 0009.
 */

public class WiFiListExtDevAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    private List<HiChipDefines.SWifiAp_Ext> wifi_list_ext = Collections.synchronizedList(new ArrayList<HiChipDefines.SWifiAp_Ext>());
    private String[] videoApenc;

    public WiFiListExtDevAdapter(Context context, List<HiChipDefines.SWifiAp_Ext> wifi_list_ext) {
        this.mInflater = LayoutInflater.from(context);
        this.wifi_list_ext=wifi_list_ext;
        videoApenc = context.getResources().getStringArray(R.array.video_apenc);
    }

    @Override
    public int getCount() {
        return wifi_list_ext.size();
    }

    @Override
    public Object getItem(int position) {
        return wifi_list_ext.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("InflateParams")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final HiChipDefines.SWifiAp_Ext wifi = wifi_list_ext.get(position);

        if (wifi == null)
            return null;

        ViewHolder holder = null;

        if (convertView == null) {

            convertView = mInflater.inflate(R.layout.list_setting_wifi, null);

            holder = new ViewHolder();
            holder.txt_ssid = (TextView) convertView.findViewById(R.id.wifi_setting_item_ssid);
            holder.txt_safety = (TextView) convertView.findViewById(R.id.wifi_setting_item_safety);
            holder.txt_intensity = (TextView) convertView.findViewById(R.id.wifi_setting_item_signal_intensity);
            // holder.txt_state=(TextView)convertView.findViewById(R.id.wifi_setting_item_state);
            convertView.setTag(holder);

        } else {

            holder = (ViewHolder) convertView.getTag();
        }

        if (holder != null) {
            try {
                holder.txt_ssid.setText(new String(wifi.strSSID, "UTF-8"));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            // holder.txt_ssid.setText(Packet.getString(icon_wifi.strSSID));
            holder.txt_safety.setText(videoApenc[wifi.EncType]);
            String strSignal = wifi.Signal + "" + "%";
            holder.txt_intensity.setText(strSignal);
        }

        return convertView;

    }

    public final class ViewHolder {
        public TextView txt_ssid;
        public TextView txt_safety;
        public TextView txt_intensity;
        // public TextView txt_state;
    }

}
